package com.grandbroad.eim.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.base.bean.VodBean;
import com.grandbroad.eim.R;
import com.grandbroad.eim.ui.activities.VideoActivity;
import com.grandbroad.eim.utils.TimeUtils;
import com.grandbroad.eim.utils.UiUtlis;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 通用的视频列表视频器
 */
public class VodListAdpter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    private AppCompatActivity appCompatActivity;
    private List<VodBean> vodList = new ArrayList<>();

    public void setVodList(List<VodBean> vodList) {
        this.vodList = vodList;
    }

    public VodListAdpter(AppCompatActivity appCompatActivity)
    {
        this.appCompatActivity = appCompatActivity;
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.class_item, viewGroup, false);
        return new VodListViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
        if (viewHolder instanceof VodListViewHolder) {
            final VodBean vodBean = vodList.get(i);
            VodListViewHolder listViewHolder = (VodListViewHolder) viewHolder;
            x.image().bind(listViewHolder.imgClassItem, vodBean.getCover_img());
            listViewHolder.tvVodName.setText(vodBean.getName());
            listViewHolder.tvSeeCount.setText(vodBean.getCount()+"");
            listViewHolder.tvVodTime.setText(TimeUtils.getInstance().formatGTtime(vodBean.getCreated_at()));
            listViewHolder.tvVodUsername.setText(vodBean.getUser().getName());
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    UiUtlis.startAnimActivity(appCompatActivity,VideoActivity.class,v,"screen_img","bean",vodBean,false);

                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return vodList.size();
    }

    /***
     * 列表viewholder
     */
    class VodListViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_class_item)
        ImageView imgClassItem;
        @BindView(R.id.tv_see_count)
        TextView tvSeeCount;
        @BindView(R.id.tv_vod_name)
        TextView tvVodName;
        @BindView(R.id.tv_vod_username)
        TextView tvVodUsername;
        @BindView(R.id.tv_vod_time)
        TextView tvVodTime;
        public VodListViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
